package com.atguigu.yygh.cmn.listener;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.read.listener.ReadListener;
import com.atguigu.yygh.cmn.mapper.DictMapper;
import com.atguigu.yygh.model.cmn.Dict;
import com.atguigu.yygh.vo.cmn.DictEeVo;
import org.springframework.beans.BeanUtils;

/**
 * @ClassName DictListener
 * @Description: 类描述
 * @Author: admin
 * @CreateDate: 2024/6/1 15:08
 * @UpdateUser: 更新人
 * @UpdateDate: 2024/6/1 15:08
 * @UpdateRemark: 更新的信息
 * @Version: 1.0
 */


public class DictListener implements ReadListener<DictEeVo> {
    //通过有参构造器注入DictMapper
    private DictMapper dictMapper;
    public DictListener(DictMapper dictMapper) {
        this.dictMapper = dictMapper;
    }

    /**
     * 每读取一行调用一次invoke
     * @param dictEeVo
     * @param analysisContext
     */
    @Override
    public void invoke(DictEeVo dictEeVo, AnalysisContext analysisContext) {
        Dict dict = new Dict();
        //将DictEeVo对象属性复制到Dict对象中
        BeanUtils.copyProperties(dictEeVo, dict);
//        System.out.println("读取到一条数据:" + dict);
        dictMapper.insert(dict);
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {

    }
}
